package com.gitee.zycra.future.job.common.vo;

import com.gitee.zycra.future.job.common.model.JobRunning;
import com.gitee.zycra.future.job.common.model.JobScheduleLog;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Accessors;

import java.time.LocalDateTime;

/**
 * @author zycra
 */
@Getter
@Setter
@ToString
@Accessors(chain = true)
public class JobRunningVO {

    /**
     * 主键
     */
    private Long id;

    /**
     * 任务名称
     */
    private String jobName;

    /**
     * 调度名称
     */
    private String scheduleName;

    /**
     * 任务类名
     */
    private String jobClassName;

    /**
     * 任务调度ID
     */
    private Long jobScheduleId;

    /**
     * 应用名称
     */
    private String applicationName;

    /**
     * 节点IP
     */
    private String nodeIp;

    /**
     * 执行参数
     */
    private String scheduleParam;

    /**
     * 发起时间
     */
    private LocalDateTime scheduleTime;

    /**
     * 正常发起时间
     */
    private LocalDateTime normalScheduleTime;

    /**
     * 重试次数
     */
    private Integer retryTimes;

    /**
     * 任务进度
     *
     * @see com.gitee.zycra.future.job.common.enums.ScheduleRatioEnum
     */
    private Integer scheduleRatio;

    /**
     * 结束时间
     */
    private LocalDateTime completeTime;

    public static JobRunningVO buildJobRunningVO(JobRunning jobRunning) {
        if (jobRunning == null) {
            return null;
        }
        return new JobRunningVO()
                .setId(jobRunning.getId())
                .setJobName(jobRunning.getJobName())
                .setScheduleName(jobRunning.getScheduleName())
                .setJobClassName(jobRunning.getJobClassName())
                .setJobScheduleId(jobRunning.getJobScheduleId())
                .setApplicationName(jobRunning.getApplicationName())
                .setNodeIp(jobRunning.getNodeIp())
                .setScheduleParam(jobRunning.getScheduleParam())
                .setScheduleTime(jobRunning.getScheduleTime())
                .setNormalScheduleTime(jobRunning.getNormalScheduleTime())
                .setRetryTimes(jobRunning.getRetryTimes())
                .setScheduleRatio(jobRunning.getScheduleRatio())
                .setCompleteTime(jobRunning.getCompleteTime());
    }

    public static JobRunningVO buildJobRunningVO(JobScheduleLog jobScheduleLog) {
        if (jobScheduleLog == null) {
            return null;
        }
        return new JobRunningVO()
                .setId(jobScheduleLog.getId())
                .setJobName(jobScheduleLog.getJobName())
                .setScheduleName(jobScheduleLog.getScheduleName())
                .setJobClassName(jobScheduleLog.getJobClassName())
                .setJobScheduleId(jobScheduleLog.getJobScheduleId())
                .setApplicationName(jobScheduleLog.getApplicationName())
                .setNodeIp(jobScheduleLog.getNodeIp())
                .setScheduleParam(jobScheduleLog.getScheduleParam())
                .setScheduleTime(jobScheduleLog.getScheduleTime())
                .setNormalScheduleTime(jobScheduleLog.getNormalScheduleTime())
                .setRetryTimes(jobScheduleLog.getRetryTimes())
                .setScheduleRatio(jobScheduleLog.getScheduleRatio())
                .setCompleteTime(jobScheduleLog.getCompleteTime());
    }
}
